package com.sptpc.demo1.model;

import com.sptpc.demo1.model.Drink;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;


//反射
// 订单
@Entity
@Table(name = "t_order")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer id;

    @Column(updatable = false)
    @CreationTimestamp
    private LocalDateTime createTime;

    private String customer;

    public Integer state;

    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    private Money price;



    @ManyToMany
    @JoinTable(name = "t_order_drink", joinColumns = {@JoinColumn(name = "drink_order_id")})
    private List<Drink> items;

//    @Override
//    public String toString() {
//        return "Order{" +
//                "id =" + id +
//                ", customer='" + customer +
//                ", state=" + state +
//                ", items=" + items +
//                ", price=" + price.getAmount() +
//                "} ";
//    }

}